package com.wolfking.datasource;

import java.sql.Connection;
import java.util.concurrent.atomic.AtomicInteger;

public class ThreadReuseContext {

    private final Connection connection;

    private final AtomicInteger count;


    public ThreadReuseContext(Connection connection) {
        this.connection = connection;
        count = new AtomicInteger(1);
    }

    public void increase() {
        count.getAndIncrement();
    }

    public void decrease() {
        count.getAndDecrement();
    }

    public boolean canGet(){
        return count.get() == 0;
    }

    public Connection getConnection(){
        return connection;
    }
}
